package com.exam.bean.subject;

import java.io.Serializable;
import java.util.Set;
import java.util.HashSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;


/**
 * 知识点
 *
 */
@Entity
public class KnowledgePoint implements Serializable{
	
	private static final long serialVersionUID = -1705398045851599959L;

	private Integer id;
	private String name;//知识点
	private String note;//描述
	private Boolean visible=true;//是否可见
	private Set<KnowledgePoint> childs=new HashSet<KnowledgePoint>();//知识点
	private KnowledgePoint parent;//上级知识点
	private Set<Question> questions=new HashSet<Question>();
	
	public KnowledgePoint() {}
	
	public KnowledgePoint(Integer id) {
		this.id = id;
	}

	public KnowledgePoint(String name, String note) {
		this.name = name;
		this.note = note;
	}

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}

	@Column(length=50,nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	@Column(length=200)
	public String getNote() {
		return note;
	}
	public void setNote(String note) {
		this.note = note;
	}

	@Column(nullable=false)
	public Boolean getVisible() {
		return visible;
	}
	public void setVisible(Boolean visible) {
		this.visible = visible;
	}

	@OneToMany(cascade={CascadeType.REFRESH,CascadeType.REMOVE},mappedBy="parent")
	public Set<KnowledgePoint> getChilds() {
		return childs;
	}
	public void setChilds(Set<KnowledgePoint> childs) {
		this.childs = childs;
	}

	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="parnetid")
	public KnowledgePoint getParent() {
		return parent;
	}
	public void setParent(KnowledgePoint parent) {
		this.parent = parent;
	}

	@OneToMany(mappedBy="point",cascade=CascadeType.REMOVE)
	public Set<Question> getQuestions() {
		return questions;
	}
	public void setQuestions(Set<Question> questions) {
		this.questions = questions;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		KnowledgePoint other = (KnowledgePoint) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
